import { useUserStore } from "@/store/user";
import router from "@/router";

export function logout(before?: () => void, after?: () => void) {
  let userStore = useUserStore();
  before && before();
  // 清除token
  localStorage.removeItem("token");
  // 清空动态路由
  userStore.router.forEach((item) => router.removeRoute(item.name));
  // 清除pinia
  userStore.username = "";
  userStore.menus = [];
  // 跳转到login
  router.push("/login");

  after && after();
}
